package com.mdd.admin.controller.yylq;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.yylq.ITAppProvinceService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.yylq.TAppProvinceCreateValidate;
import com.mdd.admin.validate.yylq.TAppProvinceSearchValidate;
import com.mdd.admin.validate.yylq.TAppProvinceUpdateValidate;
import com.mdd.admin.vo.yylq.TAppProvinceDetailVo;
import com.mdd.admin.vo.yylq.TAppProvinceListedVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@ApiIgnore
@RestController
@RequestMapping("api/province")
@Api(tags = "羊羊领企---省份管理")
public class TAppProvinceController {

    @Resource
    ITAppProvinceService iTAppProvinceService;

    @GetMapping("/list")
    @ApiOperation(value="省份列表")
    public AjaxResult<PageResult<TAppProvinceListedVo>> list(@Validated PageValidate pageValidate,
                                                             @Validated TAppProvinceSearchValidate searchValidate) {
        PageResult<TAppProvinceListedVo> list = iTAppProvinceService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="省份详情")
    public AjaxResult<TAppProvinceDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        TAppProvinceDetailVo detail = iTAppProvinceService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "省份新增")
    @PostMapping("/add")
    @ApiOperation(value="省份新增")
    public AjaxResult<Object> add(@Validated @RequestBody TAppProvinceCreateValidate createValidate) {
        iTAppProvinceService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "省份编辑")
    @PostMapping("/edit")
    @ApiOperation(value="省份编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody TAppProvinceUpdateValidate updateValidate) {
        iTAppProvinceService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "省份删除")
    @PostMapping("/del")
    @ApiOperation(value="省份删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iTAppProvinceService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
